from selenium import webdriver
try:
    driver = webdriver.Chrome()
    driver.get('http://192.168.124.48:80/admin')
    # 隐式等待
    driver.implicitly_wait(10)
    # 登录
    driver.find_element_by_xpath('//*[@id="theForm"]/div/div[1]/div[2]/div[1]/input').send_keys('admin')
    driver.find_element_by_xpath('//*[@id="theForm"]/div/div[1]/div[2]/div[2]/input').send_keys('123456')
    driver.find_element_by_xpath('//*[@id="theForm"]/div/div[1]/div[2]/div[3]/input').send_keys('8888')
    driver.find_element_by_xpath('//*[@id="theForm"]/div/div[1]/div[2]/div[5]/span/input').click()
    # 点击商城
    driver.find_element_by_xpath('/html/body/div[1]/div[4]/ul/li[2]/a').click()
    # 点击促销
    driver.find_element_by_xpath('//*[@id="admincpNavTabs_shop"]/dl[3]/dt/a/h3').click()
    #点击优惠券
    driver.find_element_by_xpath('//*[@id="admincpNavTabs_shop"]/dl[3]/dd/ul/li[5]/a').click()
    # 切换iframe
    iframe = driver.find_element_by_id('workspace')
    driver.switch_to.frame(iframe)
    # 点击编辑
    driver.find_element_by_xpath('//*[@id="flexigrid"]/table/tbody/tr[1]/td[10]/div/a[3]').click()
    # 清空优惠券名称
    driver.find_element_by_xpath('//*[@id="name"]').clear()
    driver.find_element_by_xpath('//*[@id="name"]').send_keys('免费发放优惠')
    # 优惠券面额
    driver.find_element_by_xpath('//*[@id="money"]').clear()
    driver.find_element_by_xpath('//*[@id="money"]').send_keys('5')
    driver.find_element_by_xpath('//*[@id="use_start_time"]').clear()
    driver.find_element_by_xpath('//*[@id="use_start_time"]').send_keys('2021-711-11 12:00:00')
    #点击确定提交
    driver.find_element_by_xpath('//*[@id="handleposition"]/div/div/a').click()
except Exception as e:
    print(e)
# finally:
#     driver.close()